package com.yanqu.road.server.timer;

import com.yanqu.road.server.TempServer;
import com.yanqu.road.server.timer.banquet.*;
import com.yanqu.road.server.timer.beautyescort.BeautyEscortCheckTask;
import com.yanqu.road.server.timer.beautyescort.BeautyEscortRankValueTask;
import com.yanqu.road.server.timer.cross.battle.timer.task.ZhaoShangCheckTask;
import com.yanqu.road.server.timer.curio.CrossCurioTask;
import com.yanqu.road.server.timer.dataanalytics.CrossDataAnalyticsTask;
import com.yanqu.road.server.timer.grandchild.GrandChildEndExamTask;
import com.yanqu.road.server.timer.grandchild.SyncGrandChildJoinExamTask;
import com.yanqu.road.server.timer.group.*;
import com.yanqu.road.server.timer.log.CrossAutoLogSaveTask;
import com.yanqu.road.server.timer.mammonhall.MammonHallTask;
import com.yanqu.road.server.timer.match.MatchRemoveDataTask;
import com.yanqu.road.server.timer.match.MatchTask;
import com.yanqu.road.server.timer.mogulbirthday.MogulBirthdayTask;
import com.yanqu.road.server.timer.monopolymarketTask.MonopolyMarketTask;
import com.yanqu.road.server.timer.wingroom.WingRoomNotifySyncEventTask;
import com.yanqu.road.server.timer.wingroom.WingRoomUserEventDataChangeNotifyTask;
import com.yanqu.road.server.timer.workshop.WorkShopRefreshTask;
import com.yanqu.road.server.timer.zhaoshang.ZhaoShangTask;
import com.yanqu.road.task.CheckDeadLockTask;
import com.yanqu.road.task.DirectMemoryMonitorTask;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 所有的定时器写在这边
 */
public class GeneralAgentTimerMgr {

    public static final int ALL_SYNC_TIME = 300000;      //5min全同步

    private static final Logger logger = LogManager.getLogger(GeneralAgentTimerMgr.class.getName());

    private static ScheduledExecutorService timerExecutorService;

    private static MgrDataSaveTask mgrDataSaveTask = null;

    private static MgrRankDataSaveTask mgrRankDataSaveTask = null;

    private static ConnectionCheckTask connectionCheckTask = null;

    private static SyncGroupRankTask syncGroupRankTask = null;

    private static SyncGroupUnionRankTask syncGroupUnionRankTask = null;

    private static SyncGroupMammonTask syncGroupMammonTask = null;

    private static SyncAreaGroupMammonTask syncAreaGroupMammonTask = null;

    private static SyncGroupMammonRecordTask syncGroupMammonRecordTask = null;

    private static SyncAreaGroupMammonRecordTask syncAreaGroupMammonRecordTask = null;

    private static ZhaoShangTask zhaoShangTask = null;

    private static ZhaoShangCheckTask zhaoShangCheckTask = null;

    private static BeautyEscortCheckTask beautyEscortCheckTask = null;

    private static BeautyEscortRankValueTask beautyEscortRankValueTask = null;

    private static CrossDataAnalyticsTask crossDataAnalyticsTask = null;

    private static MatchTask matchTask = null;
    private static MatchRemoveDataTask matchRemoveDataTask = null;
    private static DirectMemoryMonitorTask directMemoryMonitorTask;
    private static CmdStatisticsTask cmdStatisticsTask;
    private static MonopolyMarketTask cmdMonopolyMarketTask;

    private static MammonHallTask mammonHallTask;
    private static CrossRankUploadNotifyTask crossRankUploadNotifyTask = null;

    private static SyncGrandChildJoinExamTask syncGrandChildJoinExamTask = null;
    private static GrandChildEndExamTask grandChildEndExamTask = null;

    private static LogSaveTask logSaveTask;

    private static WorkShopRefreshTask workShopRefreshTask = null;

    private static WingRoomNotifySyncEventTask wingRoomNotifySyncEventTask = null;

    private static WingRoomUserEventDataChangeNotifyTask wingRoomUserEventDataChangeNotifyTask = null;

    private static CrossCurioTask crossCurioTask = null;

    private static CheckDeadLockTask checkDeadLockTask = null;

    private static CrossAutoLogSaveTask crossAutoLogSaveTask = null;

    public static synchronized boolean initGeneralTimers(int serverType) {
        timerExecutorService = TempServer.getTimerExecutorService();

        int interval = 5;
        if (null == mgrDataSaveTask) {
            mgrDataSaveTask = new MgrDataSaveTask();
            timerExecutorService.scheduleWithFixedDelay(mgrDataSaveTask, 0, 60, TimeUnit.SECONDS);
        }

        if (null == mgrRankDataSaveTask){
            mgrRankDataSaveTask = new MgrRankDataSaveTask();
            timerExecutorService.scheduleWithFixedDelay(mgrRankDataSaveTask, 0, 60, TimeUnit.SECONDS);
        }

        if (null == connectionCheckTask) {
            connectionCheckTask = new ConnectionCheckTask(serverType);
            timerExecutorService.scheduleWithFixedDelay(connectionCheckTask, 5, 5, TimeUnit.SECONDS);
        }


       /* if (null == syncGroupRankTask) {
            syncGroupRankTask = new SyncGroupRankTask();
            timerExecutorService.scheduleWithFixedDelay(syncGroupRankTask, 10, 5, TimeUnit.SECONDS);
        }

        if (null == syncGroupUnionRankTask) {
            syncGroupUnionRankTask = new SyncGroupUnionRankTask();
            timerExecutorService.scheduleWithFixedDelay(syncGroupUnionRankTask, 10, 5, TimeUnit.SECONDS);
        }*/

        if (null == syncGroupMammonTask) {
            syncGroupMammonTask = new SyncGroupMammonTask();
            timerExecutorService.scheduleWithFixedDelay(syncGroupMammonTask, 10, 5, TimeUnit.SECONDS);
        }

        if (null == syncAreaGroupMammonTask) {
            syncAreaGroupMammonTask = new SyncAreaGroupMammonTask();
            timerExecutorService.scheduleWithFixedDelay(syncAreaGroupMammonTask, 10, 5, TimeUnit.SECONDS);
        }

        if (null == syncGroupMammonRecordTask) {
            syncGroupMammonRecordTask = new SyncGroupMammonRecordTask();
            timerExecutorService.scheduleWithFixedDelay(syncGroupMammonRecordTask, 10, 5, TimeUnit.SECONDS);
        }

        if (null == syncAreaGroupMammonRecordTask) {
            syncAreaGroupMammonRecordTask = new SyncAreaGroupMammonRecordTask();
            timerExecutorService.scheduleWithFixedDelay(syncAreaGroupMammonRecordTask, 10, 5, TimeUnit.SECONDS);
        }


        if (null == zhaoShangTask) {
            zhaoShangTask = new ZhaoShangTask();
            timerExecutorService.scheduleWithFixedDelay(zhaoShangTask, 0, 20, TimeUnit.SECONDS);
        }

        if (null == zhaoShangCheckTask) {
            zhaoShangCheckTask = new ZhaoShangCheckTask();
            timerExecutorService.scheduleWithFixedDelay(zhaoShangCheckTask, 0, 20, TimeUnit.SECONDS);
        }

        if (null == beautyEscortCheckTask){
            beautyEscortCheckTask = new BeautyEscortCheckTask();
            timerExecutorService.scheduleWithFixedDelay(beautyEscortCheckTask, 0, 20, TimeUnit.SECONDS);
        }

        if (null == beautyEscortRankValueTask){
            beautyEscortRankValueTask = new BeautyEscortRankValueTask();
            timerExecutorService.scheduleWithFixedDelay(beautyEscortRankValueTask, 20, 60, TimeUnit.SECONDS);
        }

        if (null == crossDataAnalyticsTask){
            crossDataAnalyticsTask = new CrossDataAnalyticsTask();
            timerExecutorService.scheduleWithFixedDelay(crossDataAnalyticsTask, 0, 10, TimeUnit.SECONDS);
        }

        if (null == matchTask) {
            matchTask = new MatchTask();
            timerExecutorService.scheduleWithFixedDelay(matchTask, 15, 60, TimeUnit.SECONDS);
        }

        if (null == matchRemoveDataTask) {
            matchRemoveDataTask = new MatchRemoveDataTask();
            timerExecutorService.scheduleWithFixedDelay(matchRemoveDataTask, 0, 60, TimeUnit.SECONDS);
        }

        if (directMemoryMonitorTask == null) {
            directMemoryMonitorTask = new DirectMemoryMonitorTask();
            timerExecutorService.scheduleWithFixedDelay(directMemoryMonitorTask, 60, 60, TimeUnit.SECONDS);
        }

        if (checkDeadLockTask == null) {
            checkDeadLockTask = new CheckDeadLockTask();
            timerExecutorService.scheduleWithFixedDelay(checkDeadLockTask, 0, 30, TimeUnit.SECONDS);
        }

        if (cmdStatisticsTask == null) {
            cmdStatisticsTask = new CmdStatisticsTask();
            timerExecutorService.scheduleWithFixedDelay(cmdStatisticsTask, 60, 30, TimeUnit.SECONDS);
        }

        if (mammonHallTask == null) {
            mammonHallTask = new MammonHallTask();
            timerExecutorService.scheduleWithFixedDelay(mammonHallTask, 60, 60, TimeUnit.SECONDS);
        }

        if (crossRankUploadNotifyTask == null) {
            crossRankUploadNotifyTask = new CrossRankUploadNotifyTask();
            timerExecutorService.scheduleWithFixedDelay(crossRankUploadNotifyTask, 30, 60, TimeUnit.SECONDS);
        }

        if(cmdMonopolyMarketTask == null){
            cmdMonopolyMarketTask = new MonopolyMarketTask();
            timerExecutorService.scheduleWithFixedDelay(cmdMonopolyMarketTask, 60, 5, TimeUnit.SECONDS);
        }

        if(logSaveTask == null){
            logSaveTask = new LogSaveTask();
            timerExecutorService.scheduleWithFixedDelay(logSaveTask, 60, 60, TimeUnit.SECONDS);
        }

        if (syncGrandChildJoinExamTask == null) {
            syncGrandChildJoinExamTask = new SyncGrandChildJoinExamTask();
            timerExecutorService.scheduleWithFixedDelay(syncGrandChildJoinExamTask, 10, 1, TimeUnit.SECONDS);
        }


        if (grandChildEndExamTask == null) {
            grandChildEndExamTask = new GrandChildEndExamTask();
            timerExecutorService.scheduleWithFixedDelay(grandChildEndExamTask, 15, 5, TimeUnit.SECONDS);
        }
        if (workShopRefreshTask == null) {
            workShopRefreshTask = new WorkShopRefreshTask();
            timerExecutorService.scheduleWithFixedDelay(workShopRefreshTask, 1, 1, TimeUnit.SECONDS);
        }

        if (wingRoomNotifySyncEventTask == null) {
            wingRoomNotifySyncEventTask = new WingRoomNotifySyncEventTask();
            timerExecutorService.scheduleWithFixedDelay(wingRoomNotifySyncEventTask, 10, 60, TimeUnit.SECONDS);
        }

        if (wingRoomUserEventDataChangeNotifyTask == null) {
            wingRoomUserEventDataChangeNotifyTask = new WingRoomUserEventDataChangeNotifyTask();
            timerExecutorService.scheduleWithFixedDelay(wingRoomUserEventDataChangeNotifyTask, 10, 10, TimeUnit.SECONDS);
        }

        if (null == crossCurioTask){
            crossCurioTask = new CrossCurioTask();
            timerExecutorService.scheduleWithFixedDelay(crossCurioTask, 1, 1, TimeUnit.MINUTES);
        }

        if (null == crossAutoLogSaveTask) {
            crossAutoLogSaveTask = new CrossAutoLogSaveTask();
            timerExecutorService.scheduleWithFixedDelay(crossAutoLogSaveTask, 60, 30, TimeUnit.SECONDS);
        }

        return true;
    }
}
